package com.springboot.scheduled.demo.controller;

import com.springboot.scheduled.demo.service.DynamicTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * 动态管理定时任务的Controller
 */
@RestController
@RequestMapping("/")
public class DynamicTaskController {

    @Autowired
    private DynamicTaskService dynamicTaskService;

    @GetMapping("add/{id}")
    public String add(@PathVariable String id) {
        System.out.println("id = " + id + "- " + LocalDateTime.now());
        return dynamicTaskService.addAndStartTask(id);
    }

    @GetMapping("del/{id}")
    public String del(@PathVariable String id) {
        System.out.println("id = " + id + "- " + LocalDateTime.now());
        return dynamicTaskService.stopAndDelTask(id);
    }
}
